package metaRobot;

import robocode.*;
import robocode.util.Utils;
import java.awt.Color;
import java.awt.geom.Point2D;
		
public class Robot_9_94 extends ACRobot
{
	private Point2D.Double _enemyLocation;
	
	public void run() 
	{
		setColors(Color.black, Color.green, Color.yellow, Color.green, Color.red);
		setAdjustRadarForGunTurn(true);	
		while(true) 
		{
						moveToEnemy(_enemyLocation);
			moveToEnemy(_enemyLocation);
			setTurnRadarRight(360);

			
			execute();
		}
	}
	
	public void onScannedRobot(ScannedRobotEvent e) 
	{
		// aggiorna la posizione del nemico
		double absBearing = e.getBearingRadians() + getHeadingRadians();
		_enemyLocation = project(new Point2D.Double(getX(), getY()), absBearing, e.getDistance());
		
		if (e.getEnergy() < 10) { 
			if (testEnemyWithinTicksOfFire(e, 50, 2)) { 
				if (testEnemyWithinTicksOfFire(e, 20, 3)) { 
					setFire(2);
				} 
				else { 
					turnGunToEnemy(_enemyLocation);
				}
			} 
			else { 
				if (testEnemyWithinTicksOfFire(e, 50, 3)) { 
					turnGunRight(10);
				} 
				else { 
					turnGunRight(10);
				}
			}
		} 
		else { 
			setFire(3);
			if (testEnemyWithinTicksOfFire(e, 50, 2)) { 
				if (getGunHeat() > 0) { 
					if (testEnemyWithinTicksOfFire(e, 50, 3)) { 
						setFire(3);
					} 
					else { 
						turnGunRight(10);
					}
				} 
				else { 
					noOperation();
					setFire(2);
				}
			} 
			else { 
				if (testEnemyWithinTicksOfFire(e, 50, 3)) { 
					setFire(3);
				} 
				else { 
					turnGunRight(10);
				}
			}
		}


		execute();
	}
	
	public void onHitByBullet(HitByBulletEvent e) 
	{
		setAhead(50);


		execute();
	}

	public void onHitWall(HitWallEvent e) 
	{
		if (testEnemyWithinTicks(_enemyLocation, 30)) { 
			if (testEnemyWithinTicks(_enemyLocation, 10)) { 
				move(false, 150, true, 90);
			} 
			else { 
				noOperation();
			}
		} 
		else { 
			move(true, 150, false, 45);
		}


		execute();
	}
	
	public void onHitRobot(HitRobotEvent e) 
	{
		if (e.getEnergy() < 0.05) { 
			if (getGunHeat() > 0) { 
				move(false, 150, false, 10);
			} 
			else { 
				move(false, 150, false, 10);
			}
		} 
		else { 
			move(false, 50, false, 90);
		}


		execute();
	}
}